home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kfilemetainfo.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-05-22  |  57.0 KB  |  1,739 lines

  1. /*
  2.  *  This file is part of the KDE libraries
  3.  *  Copyright (C) 2001-2002 Rolf Magnus <ramagnus@kde.org>
  4.  *  Copyright (C) 2001-2002 Carsten Pfeiffer <pfeiffer@kde.org>
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation version 2.0.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public License
  16.  *  along with this library; see the file COPYING.LIB.  If not, write to
  17.  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  *  Boston, MA 02110-1301, USA.
  19.  */
  20. #ifndef KILEMETAINFO_H
  21. #define KILEMETAINFO_H
  22.  
  23. /* Hack for HPUX: Namespace pollution
  24.    m_unit is a define in <sys/sysmacros.h> */
  25. #define m_unit outouftheway_m_unit
  26.  
  27. #include <qdict.h>
  28. #include <qvariant.h>
  29. #include <qobject.h>
  30. #include <qstring.h>
  31. #include <kurl.h>
  32.  
  33. #undef m_unit
  34.  
  35. class QValidator;
  36. class KFilePlugin;
  37. class KFileMetaInfoGroup;
  38.  
  39. /**
  40.  * @brief Represents the capabilities of a KFilePlugin for a given mimetype
  41.  *
  42.  * This class provides information about the capabilities that a
  43.  * KFilePlugin for a given mimetype has. It includes a list of metainfo
  44.  * groups and items together with their type, a prefix, suffix and some other
  45.  * information about how to use, display or edit the items.
  46.  *
  47.  * @author Rolf Magnus
  48.  * @author Carsten Pfeiffer
  49.  */
  50. class KIO_EXPORT KFileMimeTypeInfo
  51. {
  52.     // the plugin needs to be a friend because it puts the data into the object,
  53.     // and it should be the only one allowed to do this.
  54.     friend class KFilePlugin;
  55.     friend class KFileMetaInfoProvider;
  56.  
  57. public:
  58.     KFileMimeTypeInfo() {}
  59.  
  60.     /**
  61.      * This enum is used to specify some attributes that an item can have,
  62.      * which fit neither in the Hint nor in the Unit enum.
  63.      */
  64.     enum Attributes
  65.     {
  66.         Addable     =  1, ///< The item or group can be added by a user
  67.         Removable   =  2, ///< It can be removed
  68.         Modifiable  =  4, ///< The value can be edited (no meaning for a group)
  69.         Cumulative =  8,  /**< If an application wants to display information
  70.                                for more than one file, it may add up the values
  71.                                for this item (e.g. play time of an mp3 file) */
  72.         Cummulative = Cumulative, ///< @deprecated Use Cumulative instead
  73.         Averaged    = 16, /**< Similar to Cumulative, but the average should
  74.                                be calculated instead of the sum */
  75.         MultiLine   = 32, /**< This attribute says that a string item is likely
  76.                                to be more than one line long, so for editing, a
  77.                                widget capable for multline text should be used
  78.                                @since 3.1 */
  79.         SqueezeText = 64  /**< If the text for this item is very long, it
  80.                                should be squeezed to the size of the widget
  81.                                where it's displayed
  82.                                @since 3.1 */
  83.     };
  84.  
  85.     /**
  86.      * This enum is mainly for items that have a special meaning for some
  87.      * applications.
  88.      */
  89.     enum Hint {
  90.         NoHint      = 0, ///< No hint
  91.         Name        = 1, ///< The name or title of the document
  92.         Author      = 2, ///< The one who created the contents of it
  93.         Description = 3, ///< Description Some information about the document
  94.         Width       = 4, ///< The width in pixels
  95.         Height      = 5, ///< The height in pixels
  96.         Size        = 6, ///< The size in pixels (width and height)
  97.         Bitrate     = 7, ///< For media files
  98.         Length      = 8, ///< The length of the file, also for media files
  99.         Hidden      = 9, ///< The item is usually not shown to the user
  100.         Thumbnail   = 10 ///< The item is a thumbnail picture of the file
  101.  
  102.     };
  103.  
  104.     /**
  105.      * This enum exists so that you can specify units for items, which you
  106.      * can usually use for integer items, so an application knows how to
  107.      * display it (e.g. a time in seconds in a hh:mm:ss form). You can either
  108.      * use one of those units, or if you don't find one that fits, you can
  109.      * add it yourself using a prefix and/or suffix.
  110.      */
  111.     enum Unit {
  112.         NoUnit          = 0,  ///< None of the listed units
  113.         Seconds         = 1,  ///< The item represents a time in seconds
  114.         MilliSeconds    = 2,  ///< The item represents a time in milliseconds
  115.         BitsPerSecond   = 3,  ///< A bit rate
  116.         Pixels          = 4,  ///< For image dimensions and similar
  117.         Inches          = 5,  ///< Sizes
  118.         Centimeters     = 6,  ///< Sizes
  119.         Bytes           = 7,  ///< Some data/file size in bytes
  120.         FramesPerSecond = 8,  ///< A frame rate @since 3.1
  121.         DotsPerInch     = 9,  ///< Resolution in DPI @since 3.1
  122.         BitsPerPixel    = 10, ///< A bit depth @since 3.1
  123.         Hertz           = 11, ///< Sample rates and similar @since 3.1
  124.         KiloBytes       = 12, ///< Some data/file size in kilobytes @since 3.1
  125.         Millimeters     = 13  ///< Sizes @since 3.3
  126.     };
  127.  
  128.  
  129.     class ItemInfo;
  130.  
  131.     /**
  132.      *  @brief Information about a meta information group
  133.      *
  134.      *  This is the class for one group of items of a KFileMimeTypeInfo.
  135.      *  It contains, among other things, the information about the group's name
  136.      *  and a list of supported items.
  137.      */
  138.     class KIO_EXPORT GroupInfo
  139.     {
  140.  
  141.     friend class KFilePlugin;
  142.     friend class KFileMimeTypeInfo;
  143.     public:
  144.         /**
  145.          * Use this method to get a list of keys in the specified group that
  146.          * the plugin knows about. No variable keys.
  147.          * For a group that doesn't support variable keys, all keys that this
  148.          * group may have are returned. For a group that does support them, the
  149.          * non-variable ones are returned. See KFileMetaInfo about variable
  150.          * keys
  151.          *
  152.          * @return the list of keys supported for this mimetype
  153.          **/
  154.         QStringList supportedKeys() const
  155.         {
  156.             return m_supportedKeys;
  157.         }
  158.  
  159.         /**
  160.          * Use this method to get the name of the group. This string  doesn't
  161.          * depend on the user's locale settings
  162.          *
  163.          * @return the group name
  164.          */
  165.         const QString& name() const
  166.         {
  167.             return m_name;
  168.         }
  169.  
  170.         /**
  171.          *  Use this method to get the string to display to the user as group
  172.          *  name. This may be different to name() and it returns the
  173.          *  name in the user's language
  174.          *
  175.          *  @return the translated group name
  176.          */
  177.         const QString& translatedName() const
  178.         {
  179.             return m_translatedName;
  180.         }
  181.  
  182.        /**
  183.         *  A group object can contain several item objects (of which you can
  184.         *  get the names with supportedKeys() . With this method, you can
  185.         *  get one of those item objects. See ItemInfo
  186.         *
  187.         *  @return a pointer to the item info. Don't delete this object!
  188.         */
  189.         const ItemInfo * itemInfo( const QString& key ) const;
  190.  
  191.        /**
  192.         *  Get the attributes of this group (see Attributes)
  193.         *
  194.         *  @return the attributes
  195.         */
  196.         uint attributes() const
  197.         {
  198.             return m_attr;
  199.         }
  200.  
  201.         /**
  202.          * @return true if this group supports adding or removing arbitrary
  203.          * keys, false if not.
  204.          **/
  205.         bool supportsVariableKeys() const
  206.         {
  207.             return m_variableItemInfo;
  208.         }
  209.  
  210.         /**
  211.          * If the group supports variable keys, you can query their item
  212.          * info with this method. The main reason for this is that you can
  213.          * get the type and attributes of variable keys.
  214.          *
  215.          *  @return a pointer to the item info. Don't delete this object!
  216.          **/
  217.         const ItemInfo* variableItemInfo( ) const
  218.         {
  219.             return m_variableItemInfo;
  220.         }
  221.  
  222.         /** @internal */
  223.         ~GroupInfo();
  224.     private:
  225.         /** @internal */
  226.         GroupInfo( const QString& name, const QString& translatedName);
  227.  
  228.         /** @internal */
  229.         KFileMimeTypeInfo::ItemInfo* addItemInfo( const QString& key,
  230.                                                   const QString& translatedKey,
  231.                                                   QVariant::Type type);
  232.  
  233.         /** @internal */
  234.         void addVariableInfo( QVariant::Type type, uint attr );
  235.  
  236.         QString         m_name;
  237.         QString         m_translatedName;
  238.         QStringList     m_supportedKeys;
  239.         uint            m_attr;
  240.         ItemInfo*       m_variableItemInfo;
  241.         QDict<ItemInfo> m_itemDict;
  242.  
  243.     };
  244.  
  245.     /**
  246.      *  This is the class for one item of a KFileMimeTypeInfo.
  247.      *  It contains every information about a KFileMetaInfoItem that this
  248.      *  item has in common for each file of a specific mimetype.
  249.      **/
  250.     class KIO_EXPORT ItemInfo
  251.     {
  252.     friend class KFilePlugin;
  253.     friend class GroupInfo;
  254.     public:
  255.         /** @internal */
  256.         ItemInfo() {}     // ### should be private?
  257.  
  258.         /**
  259.          *
  260.          * This method returns a translated prefix to be displayed before the
  261.          * value. Think e.g. of the $ in $30
  262.          *
  263.          * @return the prefix
  264.          */
  265.         const QString& prefix() const
  266.         {
  267.             return m_prefix;
  268.         }
  269.  
  270.         /**
  271.          * This method returns a translated suffix to be displayed after the
  272.          * value. Think of the kbps in 128kbps
  273.          *
  274.          * @return the prefix
  275.          */
  276.         const QString& suffix() const
  277.         {
  278.             return m_suffix;
  279.         }
  280.  
  281.         /**
  282.          * The items for a file are stored as a QVariant and this method
  283.          * can be used to get the data type of this item.
  284.          *
  285.          * @return the QVariant type
  286.          */
  287.         QVariant::Type type() const
  288.         {
  289.             return m_type;
  290.         }
  291.  
  292.         /**
  293.          * Returns the name of the item.
  294.          * @return the name of the item
  295.          */
  296.         const QString& key() const
  297.         {
  298.             return m_key;
  299.         }
  300.  
  301.         /**
  302.          * Returns a string for the specified @p value, if possible. If not,
  303.          * QString::null is returned. This can be used by programs if they want
  304.          * to display a sum or an average of some item for a list of files.
  305.          *
  306.          * @param value the value to convert
  307.          * @param mangle if true, the string will already contain prefix and
  308.          *               suffix
  309.          * @return the converted string, or QString::null if not possible
  310.          * @since 3.1
  311.          */
  312.         QString string( const QVariant& value, bool mangle = true ) const;
  313.  
  314.         /**
  315.          * Is this item the variable item?
  316.          *
  317.          * @return true if it is, false if not
  318.          */
  319.         bool isVariableItem() const
  320.         {
  321.             // every valid item is supposed to have a non-null key
  322.             return key().isNull();
  323.         }
  324.  
  325.         /**
  326.          * Returns a translation of the key for displaying to the user. If the
  327.          * plugin provides translation to the key, it's also in the user's
  328.          * language.
  329.          * @return the translated key
  330.          */
  331.         const QString& translatedKey() const
  332.         {
  333.             return m_translatedKey;
  334.         }
  335.  
  336.         /**
  337.          * Return the attributes of the item. See
  338.          * KFileMimeTypeInfo::Attributes.
  339.          * @return the attributes
  340.          */
  341.         uint attributes() const
  342.         {
  343.             return m_attr;
  344.         }
  345.  
  346.         /**
  347.          * Return the hints for the item. See
  348.          * KFileMimeTypeInfo::Hint
  349.          * @return the hint
  350.          */
  351.         uint hint() const
  352.         {
  353.             return m_hint;
  354.         }
  355.  
  356.         /**
  357.          * Return the unit of the item. See
  358.          * KFileMimeTypeInfo::Unit
  359.          * @return the unit
  360.          */
  361.         uint unit() const
  362.         {
  363.             return m_unit;
  364.         }
  365.  
  366.     private:
  367.         /** @internal */
  368.         ItemInfo(const QString& key, const QString& translatedKey,
  369.                  QVariant::Type type)
  370.             : m_key(key), m_translatedKey(translatedKey),
  371.               m_type(type),
  372.               m_attr(0), m_unit(NoUnit), m_hint(NoHint),
  373.               m_prefix(QString::null), m_suffix(QString::null)
  374.         {}
  375.  
  376.         QString           m_key;
  377.         QString           m_translatedKey;
  378.         QVariant::Type    m_type;
  379.         uint              m_attr;
  380.         uint              m_unit;
  381.         uint              m_hint;
  382.         QString           m_prefix;
  383.         QString           m_suffix;
  384.     };
  385.  
  386.     // ### could it be made private? Would this be BC?
  387.     ~KFileMimeTypeInfo();
  388.  
  389.     /**
  390.      * Creates a validator for this item. Make sure to supply a proper
  391.      * @p parent argument or delete the validator yourself.
  392.      *
  393.      * @param group the group of the item
  394.      * @param key the key of the item
  395.      * @param parent the parent of the QObject, or 0 for a parent-less object
  396.      * @param name the name of the QObject, can be 0
  397.      * @return the validator. You are responsible for deleting it. 0 if
  398.      *         creation failed
  399.      */
  400.     QValidator * createValidator(const QString& group, const QString& key,
  401.                                  QObject *parent = 0, const char *name = 0) const;
  402.  
  403.     /**
  404.      * Returns the list of all groups that the plugin for this mimetype
  405.      * supports.
  406.      *
  407.      * @return the list of groups
  408.      */
  409.     QStringList supportedGroups() const;
  410.  
  411.     /**
  412.      * Same as the above function, but returns the strings to display to the
  413.      * user.
  414.      *
  415.      * @return the list of groups
  416.      */
  417.     QStringList translatedGroups() const;
  418.  
  419.     /**
  420.      * This returns the list of groups in the preferred order that's specified
  421.      * in the .desktop file.
  422.      *
  423.      * @return the list of groups
  424.      */
  425.     QStringList preferredGroups() const
  426.     {
  427.         return m_preferredGroups;
  428.     }
  429.  
  430.     /**
  431.      * Returns the mimetype to which this info belongs.
  432.      *
  433.      * @return the mimetype of this info
  434.      */
  435.     QString mimeType()  const {return m_mimeType;}
  436.  
  437.     /**
  438.      * Get the group info for a specific group.
  439.      *
  440.      * @param group the group whose group info should be retrieved
  441.      * @return a pointer to the info. 0 if it does not
  442.      *         exist. Don't delete this object!
  443.      */
  444.     const GroupInfo * groupInfo( const QString& group ) const;
  445.  
  446.     // always returning stringlists which the user has to iterate and use them
  447.     // to look up the real items sounds strange to me. I think we should add
  448.     // our own iterators some time (somewhere in the future ;)
  449.  
  450.     /**
  451.      * Return a list of all supported keys without looking for a specific
  452.      * group
  453.      *
  454.      * @return the list of keys
  455.      */
  456.     QStringList supportedKeys() const;
  457.  
  458.     /**
  459.      * Return a list of all supported keys in preference order
  460.      *
  461.      * @return the list of keys
  462.      */
  463.     QStringList preferredKeys() const
  464.     {
  465.         return m_preferredKeys;
  466.     }
  467.  
  468.     // ### shouldn't this be private? BC?
  469.     GroupInfo * addGroupInfo( const QString& name,
  470.                               const QString& translatedName);
  471.  
  472.     QString         m_translatedName;
  473.     QStringList     m_supportedKeys;
  474.     uint            m_attr;
  475.     //        bool            m_supportsVariableKeys : 1;
  476.     QDict<ItemInfo> m_itemDict;
  477.  
  478. // ### this should be made private instead, but this would be BIC
  479. protected:
  480.     /** @internal */
  481.     KFileMimeTypeInfo( const QString& mimeType );
  482.  
  483.     QDict<GroupInfo> m_groups;
  484.     QString     m_mimeType;
  485.     QStringList m_preferredKeys;   // same as KFileMetaInfoProvider::preferredKeys()
  486.     QStringList m_preferredGroups; // same as KFileMetaInfoProvider::preferredKeys()
  487. };
  488.  
  489.  
  490. /**
  491.  * @brief A meta information item about a file
  492.  *
  493.  * This is one item of the meta information about a file (see
  494.  * KFileMetaInfo).
  495.  */
  496. class KIO_EXPORT KFileMetaInfoItem
  497. {
  498. public:
  499.     class Data;
  500.     typedef KFileMimeTypeInfo::Hint Hint;
  501.     typedef KFileMimeTypeInfo::Unit Unit;
  502.     typedef KFileMimeTypeInfo::Attributes Attributes;
  503.  
  504.     /**
  505.      * @internal
  506.      * You usually don't need to use this constructor yourself. Let
  507.      * KFileMetaInfo do it for you.
  508.      **/
  509.     // ### hmm, then it should be private
  510.     KFileMetaInfoItem( const KFileMimeTypeInfo::ItemInfo* mti,
  511.                        const QString& key, const QVariant& value);
  512.  
  513.     /**
  514.      * Copy constructor
  515.      **/
  516.     KFileMetaInfoItem( const KFileMetaInfoItem & item );
  517.  
  518.     /**
  519.      * The assignment operator, so you can do:
  520.      * @code
  521.      *    KFileMetaInfoItem item = info.item("Title");
  522.      * @endcode
  523.      *
  524.      * This will create a shared copy of the object. The actual data
  525.      * is automatically deleted if all copies go out of scope
  526.      **/
  527.     const KFileMetaInfoItem& operator= (const KFileMetaInfoItem & item );
  528.  
  529.     /**
  530.      * Default constructor. This creates an "invalid" item
  531.      */
  532.     KFileMetaInfoItem();
  533.  
  534.     ~KFileMetaInfoItem();
  535.  
  536.     /**
  537.      * Returns the key of the item.
  538.      *
  539.      * @return the key of this item
  540.      */
  541.     QString key() const;
  542.  
  543.     /**
  544.      * Returns a translation of the key for displaying to the user. If the
  545.      * plugin provides translation to the key, it's also in the user's language
  546.      *
  547.      * @return the translated key
  548.      */
  549.     QString translatedKey() const;
  550.  
  551.     /**
  552.      * Returns the value of the item.
  553.      *
  554.      * @return the value of the item.
  555.      */
  556.     const QVariant& value() const;
  557.  
  558.     /**
  559.      * Returns a string containing the value, if possible. If not,
  560.      * QString::null is returned.
  561.      *
  562.      * @param mangle if true, the string will already contain prefix and
  563.      * suffix
  564.      * @return the value string, or QString::null if not possible
  565.      */
  566.     QString string( bool mangle = true ) const;
  567.  
  568.     /**
  569.      * Changes the value of the item.
  570.      *
  571.      * @param value the new value
  572.      * @return true if successful, false otherwise
  573.      */
  574.     bool setValue( const QVariant& value );
  575.  
  576.     /**
  577.      * Return the type of the item.
  578.      *
  579.      * @return the type of the item
  580.      */
  581.     QVariant::Type type() const;
  582.  
  583.     /**
  584.      * You can query if the application can edit the item and write it back to
  585.      * the file with this method.
  586.      *
  587.      * @note This doesn't ensure that you have write access to the file and
  588.      *       that enough space is available.
  589.      *
  590.      * @return true if the item's value can be changed, false if not
  591.      */
  592.     bool isEditable() const;
  593.  
  594.     /**
  595.      * If you remove an item, it is only marked for removal for the file. On
  596.      * the next KFileMetaInfo::applyChanges() , it will be removed from
  597.      * the file. With this method, you can ask if the item is marked for
  598.      * removal.
  599.      *
  600.      * @return true if the item was removed, false if not
  601.      */
  602.     bool isRemoved() const;
  603.  
  604.     /**
  605.      * If you change an item, it is marked as "dirty". On the next
  606.      * KFileMetaInfo::applyChanges() , the change will be written to the
  607.      * file. With this method, you can ask if this item is dirty.
  608.      *
  609.      * @return true if the item contains changes that have not yet been written
  610.      * back into the file. Removing or adding an item counts as such a change
  611.      */
  612.     bool isModified() const;
  613.  
  614.     /**
  615.      * This method returns a translated prefix to be displayed before the
  616.      * value. Think e.g. of the $ in $30
  617.      *
  618.      * @return the prefix
  619.      */
  620.     QString prefix() const;
  621.  
  622.     /**
  623.      * This method returns a translated suffix to be displayed after the
  624.      * value. Think of the kbps in 128kbps
  625.      *
  626.      * @return the suffix
  627.      */
  628.     QString suffix() const;
  629.  
  630.     /**
  631.      * Returns the hint for this item. See KFileMimeTypeInfo::Hint.
  632.      *
  633.      * @return the hint
  634.      **/
  635.     uint hint() const;
  636.  
  637.     /**
  638.      * Returns the unit for this item. See KFileMimeTypeInfo::Unit.
  639.      *
  640.      * @return the unit
  641.      * @since 3.2
  642.      **/
  643.     uint unit() const;
  644.  
  645.     /**
  646.      * Returns the attributes for this item. See
  647.      * KFileMimeTypeInfo::Attributes.
  648.      *
  649.      * @return the attributes
  650.      **/
  651.     uint attributes() const;
  652.  
  653.     /**
  654.      * Return true if the item is valid, i.e. if it contains data, false
  655.      * if it's invalid (created with the default constructor and not been
  656.      * assigned anything), or if KFileMetaInfoGroup::item() didn't find
  657.      * your requested item).
  658.      *
  659.      * @return true if valid, false if invalid
  660.      */
  661.     bool isValid() const;
  662.  
  663.     KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoItem& );
  664.     KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
  665.     KIO_EXPORT friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfoItem& );
  666.     friend class KFileMetaInfoGroup;
  667.  
  668. protected:
  669.     void setAdded();
  670.     void setRemoved();
  671.  
  672.     void ref();
  673.     void deref();
  674.  
  675.     Data *d;
  676. };
  677.  
  678. /**
  679.  * @brief A group of meta information items about a file
  680.  *
  681.  * This is one group of meta information items about a file (see
  682.  * KFileMetaInfo).
  683.  */
  684. class KIO_EXPORT KFileMetaInfoGroup
  685. {
  686.   friend class KFilePlugin;
  687.   friend class KFileMetaInfo;
  688.   KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
  689.   KIO_EXPORT friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfoGroup& );
  690.  
  691. public:
  692.     class Data;
  693.     /**
  694.      * @internal
  695.      * You usually don't need to use this constructor yourself. Let
  696.      * KFileMetaInfo do it for you.
  697.      **/
  698.     // ### hmm, then it should be private
  699.     KFileMetaInfoGroup( const QString& name, const KFileMimeTypeInfo* info );
  700.  
  701.     /**
  702.      * Copy constructor
  703.      **/
  704.     KFileMetaInfoGroup( const KFileMetaInfoGroup& original );
  705.  
  706.     /**
  707.      * The assignment operator, so you can do:
  708.      * @code
  709.      *    KFileMetaInfoGroup group = info.group("Technical");
  710.      * @endcode
  711.      *
  712.      * This will create a shared copy of the object. The actual data
  713.      * is automatically deleted if all copies go out of scope
  714.      **/
  715.     const KFileMetaInfoGroup& operator= (const KFileMetaInfoGroup& info );
  716.  
  717.     /**
  718.      * Default constructor. This creates an "invalid" item
  719.      *
  720.      * @since 3.1
  721.      */
  722.      KFileMetaInfoGroup();
  723.  
  724.     ~KFileMetaInfoGroup();
  725.  
  726.     /**
  727.      * Returns true if the item is valid, i.e. if it contains data, false
  728.      * if it's invalid (created with the default constructor and not been
  729.      * assigned anything), or if KFileMetaInfoGroup::item() didn't find
  730.      * your requested item).
  731.      *
  732.      * @return true if valid, false if invalid
  733.      */
  734.     bool isValid() const;
  735.  
  736.     /**
  737.      * Returns false if the object contains data, true if it's empty. An
  738.      * empty group is a group with no items (amazing, isn't it?).
  739.      *
  740.      * @return true if empty, false otherwise
  741.      */
  742.     bool isEmpty() const;
  743.  
  744.     /**
  745.      * Returns true if an item as added or removed from the group.
  746.      *
  747.      * @return true if an item was added or removed from the group, otherwise
  748.      * false.
  749.      *
  750.      * @since 3.1
  751.      */
  752.     bool isModified() const;
  753.  
  754.     /**
  755.      * Operator for convenience. It does the same as item(),
  756.      * but you cannot specify a group to search in
  757.      */
  758.     KFileMetaInfoItem operator[]( const QString& key ) const
  759.     { return item( key ); }
  760.  
  761.     /**
  762.      * This method searches for the specified item.
  763.      *
  764.      * @param key the key of the item to search
  765.      * @return the specified item if found, an invalid item, if not
  766.      **/
  767.     KFileMetaInfoItem item( const QString& key ) const;
  768.  
  769.     /**
  770.      * Returns the item with the given @p hint.
  771.      *
  772.      * @param hint the hint of the item
  773.      * @return the item with the specified @p hint
  774.      **/
  775.     KFileMetaInfoItem item( uint hint ) const;
  776.  
  777.     /**
  778.      * Convenience function. Returns the value of the specified key.
  779.      * It does the same as item(key).value().
  780.      *
  781.      * @param key the key of the item to search
  782.      * @return the value with the given key
  783.      */
  784.     const QVariant value( const QString& key ) const
  785.     {
  786.         const KFileMetaInfoItem &i = item( key );
  787.         return i.value();
  788.     }
  789.  
  790.     /**
  791.      * Use this method to get a list of keys in the specified group that
  792.      * the plugin knows about. No variable keys.
  793.      * For a group that doesn't support variable keys, all keys that this
  794.      * group may have are returned. For a group that does support them, the
  795.      * non-variable ones are returned. See KFileMetaInfo about variable
  796.      * keys
  797.      *
  798.      * @return the list of keys supported for this mimetype
  799.     **/
  800.     QStringList supportedKeys() const;
  801.  
  802.     /**
  803.      * Returns true if this group supports adding or removing arbitrary
  804.      * keys, false if not.
  805.      *
  806.      * @return true is variable keys are supported, false otherwise
  807.     **/
  808.     bool supportsVariableKeys() const;
  809.  
  810.     /**
  811.      * Checks whether an item with the given @p key exists.
  812.      *
  813.      * @return true if an item for this @p key exists.
  814.      */
  815.     bool contains( const QString& key ) const;
  816.  
  817.     /**
  818.      * Returns a list of all keys.
  819.      *
  820.      * @return a list of all keys in the order they were inserted.
  821.      **/
  822.     QStringList keys() const;
  823.  
  824.     /**
  825.      * Returns a list of all keys in preference order.
  826.      *
  827.      * @return a list of all keys in preference order.
  828.      **/
  829.     QStringList preferredKeys() const;
  830.  
  831.    /**
  832.     * @return the list of possible types that the value for the specified key
  833.     *         can be. You can use this to determine the possible types for new
  834.     *         keys before you add them.
  835.     *
  836.     **/
  837.     // ### do we really want to support that?
  838.     // let's not waste time on thinking about it. Let's just kick it for now
  839.     // and add it in 4.0 if needed ;)
  840. //    const QMemArray<QVariant::Type>& types( const QString& key ) const;
  841.  
  842.    /**
  843.     * Add an item to the info. This is only possible if the specified @p key
  844.     * is in the supportedKeys list and not yet defined or if
  845.     * the group supports variable keys.
  846.     *
  847.     * @param key the key of the item
  848.     * @return the KFileMetaInfoItem for the given @p key
  849.     **/
  850.     KFileMetaInfoItem addItem( const QString& key );
  851.  
  852.     /**
  853.      * Remove this item from the meta info of the file. You cannot query
  854.      * KFileMetaInfo for a removed object, but you can query for a list of
  855.      * removed items with removedItems() if you need to.
  856.      * If you re-add it, its value will be cleared.
  857.      *
  858.      * @param key the key of the removed item
  859.      * @return true if successful, false otherwise
  860.      */
  861.     bool removeItem(const QString& key);
  862.  
  863.     /**
  864.      * Returns a list of all removed items.
  865.      *
  866.      * @return a list of all removed items
  867.      */
  868.     QStringList removedItems();
  869.  
  870.     /**
  871.      * The name of this group.
  872.      *
  873.      * @return the name of this group
  874.      */
  875.     QString name() const;
  876.  
  877.     /**
  878.      * The translated name of this group.
  879.      *
  880.      * @return the translated name of this group
  881.      *
  882.      * @since 3.2
  883.      */
  884.     QString translatedName() const;
  885.  
  886.     /**
  887.      * Returns the attributes of this item.
  888.      *
  889.      * @return the attributes
  890.      */
  891.     uint attributes() const;
  892.  
  893. protected:
  894.       void setAdded();
  895.       KFileMetaInfoItem appendItem( const QString& key, const QVariant& value);
  896.  
  897.       Data* d;
  898.       void ref();
  899.       void deref();
  900.  
  901. };
  902.  
  903.  
  904. ///////////////////////////////////////////////////////////////////
  905. ///////////////////////////////////////////////////////////////////
  906.  
  907.  
  908. /**
  909.  * @brief Meta Information about a file
  910.  *
  911.  * This is the class for objects that hold meta information about a file.
  912.  * The information is kept in form of a system of key/value pairs. See also
  913.  * KFileMetaInfoItem.
  914.  * This information is retrieved from the file through a plugin system, and
  915.  * this class is the main interface to it.
  916.  * If you want to write your own plugin, have a look at KFilePlugin.
  917.  * There are basically two different kinds of meta information: Fixed ones
  918.  * that the plugin knows about (e.g. an mp3 id3v1 tag has a well defined
  919.  * fixed list of fields), and variable keys that exist in mimetypes that
  920.  * support their own key/value system (comments in png files are of this type).
  921.  * Almost every file has fixed keys, but some also have variable keys.
  922.  *
  923.  * The groups and the What enum are not yet supported, but already added to
  924.  * the interface so that adding support doesn't break compatibility.
  925.  */
  926. class KIO_EXPORT KFileMetaInfo
  927. {
  928. public:
  929.     typedef KFileMimeTypeInfo::Hint Hint;
  930.     typedef KFileMimeTypeInfo::Unit Unit;
  931.     typedef KFileMimeTypeInfo::Attributes Attributes;
  932.     class Data;
  933.  
  934.     /**
  935.      * This is used to specify what a KFileMetaInfo object should read, so
  936.      * you can specify if you want to read "expensive" items or not.
  937.      */
  938.     enum What
  939.     {
  940.       Fastest       = 0x1,  /**< do the fastest possible read and omit all items
  941.                                  that might need a significantly longer time
  942.                                  than the others */
  943.       DontCare      = 0x2,  ///< let the plugin decide what to read
  944.  
  945.       TechnicalInfo = 0x4,  /**< extract technical details about the file, like
  946.                                  e.g. play time, resolution or a compressioni
  947.                                  type */
  948.       ContentInfo   = 0x8,  /**< read information about the content of the file,
  949.                                  like comments or id3 tags */
  950.       ExtenedAttr   = 0x10, /**< read filesystem based extended attributes if
  951.                                  they are supported for the filesystem */
  952.       Thumbnail     = 0x20, /**< only read the file's thumbnail, if it contains
  953.                                  one */
  954.       Preferred     = 0x40,  ///< get at least the preferred items
  955.       Everything    = 0xffff ///< read everything, even if it might take a while
  956.  
  957.     };
  958.  
  959.     /**
  960.      * The constructor.
  961.      *
  962.      * creating a KFileMetaInfo item through this will autoload the plugin
  963.      * belonging to the mimetype and try to get meta information about
  964.      * the specified file.
  965.      *
  966.      * If no info is available, you'll get an empty (not invalid) object.
  967.      * You can test for it with the isEmpty() method.
  968.      *
  969.      *  @param path The file name. This must be the path to a local file.
  970.      *  @param mimeType The name of the file's mimetype. If ommited, the
  971.      *         mimetype is autodetected
  972.      *  @param what one or more of the What enum values. It gives some
  973.      *              hint to the plugin what information is desired. The plugin
  974.      *              may still return more items.
  975.      *
  976.      * @note This version will @b only work for @b local (file:/) files.
  977.      *
  978.      **/
  979.     KFileMetaInfo( const QString& path,
  980.                    const QString& mimeType = QString::null,
  981.                    uint what = Fastest);
  982.  
  983.    /**
  984.     * Another constructor
  985.     *
  986.     * Similar to the above, but takes a URL so that meta-data may be retrieved
  987.     * over other protocols (ftp, etc.)
  988.     *
  989.     **/
  990.     KFileMetaInfo( const KURL& url,
  991.                    const QString& mimeType = QString::null,
  992.                    uint what = Fastest);
  993.  
  994.     /**
  995.      * Default constructor. This will create an invalid object (see
  996.      * isValid().
  997.      **/
  998.     KFileMetaInfo();
  999.  
  1000.     /**
  1001.      * Copy constructor. This creates a copy of the original object, but
  1002.      * that copy will point to the same data, so if you change the original,
  1003.      * the copy will be changed, too. After all, they are referring to the same
  1004.      * file.
  1005.      **/
  1006.     KFileMetaInfo( const KFileMetaInfo& original);
  1007.  
  1008.     ~KFileMetaInfo();
  1009.  
  1010.     /**
  1011.      * The assignment operator, so you can do e.g.:
  1012.      * @code
  1013.      *    KFileMetaInfo info;
  1014.      *    if (something) info = KFileMetaInfo("/the/file");
  1015.      * @endcode
  1016.      *
  1017.      * This will create a shared copy of the object. The actual data
  1018.      * is automatically deleted if all copies go out of scope.
  1019.      **/
  1020.     const KFileMetaInfo& operator= (const KFileMetaInfo& info );
  1021.  
  1022.  
  1023.     /**
  1024.      * Returns a list of all groups.
  1025.      *
  1026.      * @return the keys of the groups that the file has.
  1027.      */
  1028.     QStringList groups() const;
  1029.  
  1030.     /**
  1031.      * Returns a list of all supported groups.
  1032.      *
  1033.      * @return the supported keys of the groups that the file has.
  1034.      */
  1035.     QStringList supportedGroups() const;
  1036.  
  1037.     /**
  1038.      * Returns a list of the preferred groups.
  1039.      *
  1040.      * @return the keys of the preferred groups that the file has.
  1041.      */
  1042.     QStringList preferredGroups() const;
  1043.  
  1044.     /**
  1045.      * Returns a list of all preferred keys.
  1046.      *
  1047.      * @return a list of all preferred keys.
  1048.      */
  1049.     QStringList preferredKeys() const;
  1050.  
  1051.     /**
  1052.      * Returns a list of supported keys.
  1053.      *
  1054.      * @return a list of supported keys
  1055.      */
  1056.     QStringList supportedKeys() const;
  1057.  
  1058.    /**
  1059.     * Returns the list of groups that you can add or remove from the file.
  1060.     *
  1061.     * @return the groups can be added or removed
  1062.     */
  1063.     QStringList editableGroups() const;
  1064.  
  1065.     // I'd like to keep those for lookup without group, at least the hint
  1066.     // version
  1067.     /**
  1068.      * Returns the KFileMetaInfoItem with the given @p key.
  1069.      *
  1070.      * @param key the key of the item
  1071.      * @return the item. Invalid if there is no item with the given @p key.
  1072.      */
  1073.     KFileMetaInfoItem item(const QString& key) const;
  1074.     /**
  1075.      * Returns the KFileMetaInfoItem with the given @p hint.
  1076.      *
  1077.      * @param hint the hint of the item
  1078.      * @return the item. Invalid if there is no item with the given @p hint.
  1079.      */
  1080.     KFileMetaInfoItem item(const KFileMetaInfoItem::Hint hint) const;
  1081.  
  1082.     /**
  1083.      * Saves the item with the given @p key.
  1084.      *
  1085.      * @param key the key of the item
  1086.      * @param preferredGroup the preferred group, or QString::null
  1087.      * @param createGroup true to create the group if necessary
  1088.      * @return the saved item
  1089.      */
  1090.     KFileMetaInfoItem saveItem( const QString& key,
  1091.                                 const QString& preferredGroup = QString::null,
  1092.                                 bool createGroup = true );
  1093.  
  1094.     /**
  1095.      * Returns the KFileMetaInfoGroup with the given @p key.
  1096.      *
  1097.      * @param key the key of the item
  1098.      * @return the group. Invalid if there is no group with the given @p key.
  1099.      */
  1100.     KFileMetaInfoGroup group(const QString& key) const;
  1101.  
  1102.     /**
  1103.      * Returns the KFileMetaInfoGroup with the given @p key.
  1104.      *
  1105.      * @param key the key of the item
  1106.      * @return the group. Invalid if there is no group with the given @p key.
  1107.      */
  1108.     KFileMetaInfoGroup operator[] (const QString& key) const
  1109.     {
  1110.         return group(key);
  1111.     }
  1112.  
  1113.    /**
  1114.     * Try to add the specified group. This will only succeed if it is
  1115.     * in the list of editableGroups().
  1116.     *
  1117.     * @note that all non-variable items that belong to this group are
  1118.     *  automatically added as empty item.
  1119.     *
  1120.     * @param name the name of the group to add
  1121.     * @return true if successful, false if not
  1122.     */
  1123.     bool addGroup( const QString& name );
  1124.  
  1125.    /**
  1126.     * Remove the specified group. This will only succeed if it is
  1127.     * in the list of editableGroups(). Beware that this also
  1128.     * removes all the items in that group, so always ask the user
  1129.     * before removing it!
  1130.     *
  1131.     * @param name the name of the group to remove
  1132.     * @return true if successful, false if not
  1133.     */
  1134.     bool removeGroup( const QString& name );
  1135.  
  1136.     /**
  1137.      * Returns a list of removed groups.
  1138.      *
  1139.      * @return a list of removed groups.
  1140.      */
  1141.     QStringList removedGroups();
  1142.  
  1143.    /**
  1144.     * This method writes all pending changes of the meta info back to the file.
  1145.     * If any items are marked as removed, they are really removed from the
  1146.     * list. The info object as well as all items are updated.
  1147.     *
  1148.     * @return true if successful, false if not
  1149.     */
  1150.     bool applyChanges();
  1151.  
  1152.    /**
  1153.     * This method writes all pending changes of the meta info to the file @p path.
  1154.     * If any items are marked as removed, they are really removed from the
  1155.     * list. The info object as well as all items are updated.
  1156.     *
  1157.     * @return true if successful, false if not
  1158.     */
  1159.     bool applyChanges(const QString& path);
  1160.  
  1161.    /**
  1162.      * Checks whether an item with the given @p key exists.
  1163.      *
  1164.      * @param key the key to check
  1165.      * @return whether an item for this @p key exists.
  1166.      */
  1167.     bool contains( const QString& key ) const;
  1168.  
  1169.     /**
  1170.      * Checks whether a group with the given @p key exists.
  1171.      *
  1172.      * @param key the key to check
  1173.      * @return whether a group with this name exists.
  1174.      */
  1175.     bool containsGroup( const QString& key ) const;
  1176.  
  1177.     /**
  1178.      * Returns the value with the given @p key.
  1179.      *
  1180.      * @param key the key to retrieve
  1181.      * @return the value. Invalid if it does not exist
  1182.      */
  1183.     const QVariant value( const QString& key ) const
  1184.     {
  1185.         return item(key).value();
  1186.     }
  1187.  
  1188.  
  1189.     /**
  1190.      * Returns true if the item is valid, i.e. if actually represents the info
  1191.      * about a file, false if the object is uninitialized.
  1192.      *
  1193.      * @return true if valid, false otherwise
  1194.      */
  1195.     bool isValid() const;
  1196.  
  1197.     /**
  1198.      * Returns false if the object contains data, true if it's empty. You'll
  1199.      * get an empty object if no plugin for the file could be found.
  1200.      *
  1201.      * @return true if empty, false otherwise
  1202.      */
  1203.     bool isEmpty() const;
  1204.  
  1205.     /**
  1206.      * Returns the mime type of file.
  1207.      *
  1208.      * @return the file's mime type
  1209.      */
  1210.     QString mimeType() const;
  1211.  
  1212.     /**
  1213.      * Returns the path of file - or QString::null if file is non-local
  1214.      *
  1215.      * @return the file's path - or QString::null if file is non-local
  1216.      */
  1217.     QString path() const;
  1218.  
  1219.     /**
  1220.      * Returns the url of file
  1221.      *
  1222.      * @return the file's url
  1223.      */
  1224.     KURL url() const;
  1225.  
  1226.     KIO_EXPORT friend QDataStream& operator >>(QDataStream& s, KFileMetaInfo& );
  1227.     KIO_EXPORT friend QDataStream& operator <<(QDataStream& s, const KFileMetaInfo& );
  1228.     friend class KFilePlugin;
  1229.  
  1230. protected:
  1231.     KFileMetaInfoGroup appendGroup(const QString& name);
  1232.  
  1233.    /**
  1234.      * @return a pointer to the plugin that belogs to this object's mimetype.
  1235.      *         It will be auto-loaded if it's currently not loaded
  1236.      **/
  1237.     KFilePlugin * const plugin() const;
  1238.  
  1239.     void ref();
  1240.     void deref();
  1241.  
  1242.     Data* d;
  1243.  
  1244. private:
  1245.     KFileMetaInfoItem findEditableItem( KFileMetaInfoGroup& group,
  1246.                                         const QString& key );
  1247.  
  1248.     void init( const KURL& url,
  1249.                const QString& mimeType = QString::null,
  1250.                uint what = Fastest);
  1251. };
  1252.  
  1253. ///////////////////////////////////////////////////////////////////
  1254. ///////////////////////////////////////////////////////////////////
  1255.  
  1256.  
  1257. /**
  1258.  * @brief Base class for a meta information plugin
  1259.  *
  1260.  * Meta information plugins are used to extract useful information from files
  1261.  * of a given type. These plugins are used in Konqueror's file properties
  1262.  * dialog, for example.
  1263.  *
  1264.  * If you want to write your own plugin, you need to derive from this class.
  1265.  *
  1266.  * In the constructor of your class, you need to call addMimeTypeInfo() to tell
  1267.  * the KFile framework which mimetype(s) your plugin supports. For each
  1268.  * mimetype, use the addGroupInfo() and addItemInfo() methods to declare the
  1269.  * meta information items the plugin calculates and to group them accordingly.
  1270.  * For groups, use setAttributes() to customize your group (see
  1271.  * KFileMimeTypeInfo::Attributes). For items, use setAttributes() to define the
  1272.  * behaviour of the item; use setHint() to define the meaning of the item; use
  1273.  * setUnit() to define the Unit, such as KFileMimeTypeInfo::Seconds or
  1274.  * KFileMimeTypeInfo::KiloBytes. In short, the constructor defines the data
  1275.  * structure of the meta information supported by your plugin.
  1276.  *
  1277.  * Example:
  1278.  *  @code
  1279.  *  FooPlugin::FooPlugin(QObject *parent, const char *name,
  1280.  *                       const QStringList &args)
  1281.  *      : KFilePlugin(parent, name, args)
  1282.  *  {
  1283.  *      KFileMimeTypeInfo* info = addMimeTypeInfo( "application/x-foo" );
  1284.  *
  1285.  *      // our new group
  1286.  *      KFileMimeTypeInfo::GroupInfo* group = 0L;
  1287.  *      group = addGroupInfo(info, "FooInfo", i18n("Foo Information"));
  1288.  *
  1289.  *      KFileMimeTypeInfo::ItemInfo* item;
  1290.  *
  1291.  *      // our new items in the group
  1292.  *      item = addItemInfo(group, "Items", i18n("Items"), QVariant::Int);
  1293.  *      item = addItemInfo(group, "Size", i18n("Size"), QVariant::Int);
  1294.  *      setUnit(item, KFileMimeTypeInfo::KiloBytes);
  1295.  *
  1296.  *      // strings are possible, too:
  1297.  *      //addItemInfo(group, "Document Type", i18n("Document type"), QVariant::String);
  1298.  *  }
  1299.  *  @endcode
  1300.  *
  1301.  * Some meta information items are likely to be available in several different
  1302.  * file formats, such as @c "Author", @c "Title" (for documents), and
  1303.  * @c "Length" (for multimedia files). Be sure to use the naming scheme from
  1304.  * existing plugins for your meta information items if possible. If, for
  1305.  * example, the meta information of a group of files is shown in a table view,
  1306.  * this will allow two files to share the same column (say "Length") even if
  1307.  * they are of a different file type.
  1308.  *
  1309.  * You must overwrite the readInfo() method. In this method you need to extract
  1310.  * the meta information of the given file. You can use a third-party library to
  1311.  * achieve this task. This might be the best way for binary files, since a
  1312.  * change in the file format is likely to be supported by subsequent releases
  1313.  * of that library. Alternatively, for text-based file formats, you can use
  1314.  * QTextStream to parse the file. For simple file formats, QRegExp can be of
  1315.  * great help, too.
  1316.  *
  1317.  * After you extracted the relevant information, use appendGroup() and
  1318.  * appendItem() to fill the meta information data structure (as defined in the
  1319.  * constructor) with values. Note that you can leave out groups or items
  1320.  * which are not appropriate for a particular file.
  1321.  *
  1322.  * Example:
  1323.  *  @code
  1324.  *  bool FooPlugin::readInfo( KFileMetaInfo& info, uint what)
  1325.  *  {
  1326.  *      int numItems = 0;
  1327.  *      int size = 0;
  1328.  *
  1329.  *      // do your calculations here, e.g. using a third-party
  1330.  *      // library or by writing an own parser using e.g. QTextStream
  1331.  *
  1332.  *      // calculate numItems and size ...
  1333.  *
  1334.  *      // note: use the same key strings as in the constructor
  1335.  *      KFileMetaInfoGroup group = appendGroup(info, "FooInfo");
  1336.  *
  1337.  *      appendItem(group, "Items", numItems);
  1338.  *      appendItem(group, "Size", size);
  1339.  *
  1340.  *      return true;
  1341.  *  }
  1342.  *  @endcode
  1343.  *
  1344.  * If you want to define mutable meta information items, you need to overwrite
  1345.  * the writeInfo() method. In this method, you can use third-party library
  1346.  * (appropriate mostly for binary files, see above) or QTextStream to write the
  1347.  * information back to the file. If you use QTextStream, be sure to write all
  1348.  * file contents back.
  1349.  *
  1350.  * For some items, it might be that not all possible values are allowed. You
  1351.  * can overwrite the createValidator() method to define constraints for a meta
  1352.  * information item. For example, the @c "Year" field for an MP3 file could
  1353.  * reject values outside the range 1500 - 2050 (at least for now). The
  1354.  * validator is used to check values before the writeInfo() method is called so
  1355.  * that writeInfo() is only provided correct values.
  1356.  *
  1357.  * In your plugin, you need to create a factory for the KFilePlugin
  1358.  *
  1359.  * Example:
  1360.  *  @code
  1361.  *  typedef KGenericFactory<FooPlugin> FooFactory;
  1362.  *  K_EXPORT_COMPONENT_FACTORY(kfile_foo, FooFactory("kfile_foo"));
  1363.  *  @endcode
  1364.  *
  1365.  * To make your plugin available within KDE, you also need to provide a
  1366.  * @c .desktop file which describes your plugin. The required fields in the
  1367.  * file are:
  1368.  *
  1369.  * - @c Type: must be @c "Service"
  1370.  * - @c Name: the name of the plugin
  1371.  * - @c ServiceTypes: must contain @c "KFilePlugin"
  1372.  * - @c X-KDE-Library: the name of the library containing the KFile plugin
  1373.  * - @c MimeType: the mimetype(s) which are supported by the plugin
  1374.  * - @c PreferredGroups: a comma-separated list of the most important groups.
  1375.  *   This list defines the order in which the meta information groups should be
  1376.  *   displayed
  1377.  * - @c PreferredItems: a comma-separated list of the most important items.
  1378.  *   This list defines the order in which the meta information items should be
  1379.  *   displayed
  1380.  *
  1381.  * Example:
  1382.  *  @code
  1383.  *  [Desktop Entry]
  1384.  *  Encoding=UTF-8
  1385.  *  Type=Service
  1386.  *  Name=Foo Info
  1387.  *  ServiceTypes=KFilePlugin
  1388.  *  X-KDE-Library=kfile_foo
  1389.  *  MimeType=application/x-foo
  1390.  *  PreferredGroups=FooInfo
  1391.  *  PreferredItems=Items,Size
  1392.  *  @endcode
  1393.  **/
  1394. class KIO_EXPORT KFilePlugin : public QObject
  1395. {
  1396.     Q_OBJECT
  1397.  
  1398. public:
  1399.     /**
  1400.      * Creates a new KFilePlugin instance. You need to implement a constructor
  1401.      * with the same argument list as this is required by KGenericFactory
  1402.      *
  1403.      * @param parent the parent of the QObject, can be @c 0
  1404.      * @param name the name of the QObject, can be @c 0
  1405.      * @param args currently ignored
  1406.      *
  1407.      * @see addMimeTypeInfo()
  1408.      * @see addGroupInfo()
  1409.      * @see addItemInfo()
  1410.      * @see QObject()
  1411.      **/
  1412.     KFilePlugin( QObject *parent, const char *name,
  1413.                  const QStringList& args );
  1414.  
  1415.     /**
  1416.      * Destructor
  1417.      */
  1418.     virtual ~KFilePlugin();
  1419.  
  1420.     /**
  1421.      * Read the info from the file in this method and insert it into the
  1422.      * provided KFileMetaInfo object. You can get the path to the file with
  1423.      * KFileMetaInfo::path(). Use appendGroup() and appendItem() to fill
  1424.      * @p info with the extracted values
  1425.      *
  1426.      * @param info the information will be written here
  1427.      * @param what defines what to read, see KFileMetaInfo::What
  1428.      * @return @c true if successful, @c false if it failed
  1429.      *
  1430.      * @see writeInfo()
  1431.      **/
  1432.     virtual bool readInfo( KFileMetaInfo& info,
  1433.                            uint what = KFileMetaInfo::Fastest ) = 0;
  1434.  
  1435.     /**
  1436.      * Similar to the readInfo() but for writing the info back to the file.
  1437.      * If you don't have any writable keys, don't implement this method
  1438.      *
  1439.      * @param info the information that will be written
  1440.      * @return @c true if successful, @c false if it failed
  1441.      **/
  1442.     virtual bool writeInfo( const KFileMetaInfo& info ) const
  1443.     {
  1444.         Q_UNUSED(info);
  1445.         return true;
  1446.     }
  1447.  
  1448.     /**
  1449.      * This method should create an appropriate validator for the specified
  1450.      * item if it's editable or return a null pointer if not. If you don't have
  1451.      * any editable items, you don't need to implement this method.
  1452.      *
  1453.      * If you you don't need any validation, e.g. you accept any input, you can
  1454.      * simply return @c 0L, or not reimplement this method at all.
  1455.      *
  1456.      * @param mimeType the mime type
  1457.      * @param group the group name of the validator item
  1458.      * @param key the key name of the validator item
  1459.      * @param parent the QObject parent, can be @c 0
  1460.      * @param name the name of the QObject, can be @c 0
  1461.      **/
  1462.     virtual QValidator* createValidator( const QString& mimeType,
  1463.                                          const QString& group,
  1464.                                          const QString& key,
  1465.                                          QObject* parent,
  1466.                                          const char* name) const
  1467.     {
  1468.         Q_UNUSED(mimeType); Q_UNUSED(group);Q_UNUSED(key);
  1469.         Q_UNUSED(parent);Q_UNUSED(name);
  1470.         return 0;
  1471.     }
  1472.  
  1473. protected:
  1474.  
  1475.     /**
  1476.      * Call this from within your constructor to tell the KFile framework what
  1477.      * mimetypes your plugin supports.
  1478.      *
  1479.      * @param mimeType a string containing the mimetype, e.g. @c "text/html"
  1480.      * @return a KFileMimeTypeInfo object, to be used with addGroupInfo()
  1481.      **/
  1482.     KFileMimeTypeInfo * addMimeTypeInfo( const QString& mimeType );
  1483.     // ### do we need this, if it only calls the provider?
  1484.     // IMHO the Plugin shouldn't call its provider.
  1485.     // DF: yes we need this. A plugin can create more than one mimetypeinfo.
  1486.     // What sucks though, is to let plugins do that in their ctor.
  1487.     // Would be much simpler to have a virtual init method for that,
  1488.     // so that the provider can set up stuff with the plugin pointer first!
  1489.  
  1490.     /**
  1491.      * Creates a meta information group for KFileMimeTypeInfo object returned
  1492.      * by addMimeTypeInfo().
  1493.      *
  1494.      * @param info the object returned by addMimeTypeInfo()
  1495.      * @param key a unique string identifiing this group. For simplicity it is
  1496.      *        recommended to use the same string as for the translatedKey
  1497.      *        parameter
  1498.      * @param translatedKey the translated version of the key string for
  1499.      *        displaying in user interfaces. Use i18n() to translate the string
  1500.      * @return a GroupInfo object. Pass this object to addItemInfo to add meta
  1501.      *         information attributed to this group.
  1502.      *
  1503.      * @see setAttributes()
  1504.      * @see addItemInfo()
  1505.      **/
  1506.     KFileMimeTypeInfo::GroupInfo*  addGroupInfo(KFileMimeTypeInfo* info,
  1507.                       const QString& key, const QString& translatedKey) const;
  1508.  
  1509.     /**
  1510.      * Sets attributes of the GroupInfo object returned by addGroupInfo().
  1511.      *
  1512.      * @param gi the object returned by addGroupInfo()
  1513.      * @param attr the attributes for this group; these are values of type
  1514.      *        KFileMimeTypeInfo::Attributes, or'ed together
  1515.      **/
  1516.     void setAttributes(KFileMimeTypeInfo::GroupInfo* gi, uint attr) const;
  1517.  
  1518.     void addVariableInfo(KFileMimeTypeInfo::GroupInfo* gi, QVariant::Type type,
  1519.                          uint attr) const;
  1520.  
  1521.     /**
  1522.      * Adds a meta information item to a GroupInfo object as returned by
  1523.      * addGroupInfo().
  1524.      *
  1525.      * @param gi the GroupInfo object to add a new item to
  1526.      * @param key a unique string to identify this item. For simplicity it is
  1527.      *        recommended to use the same string as for the translatedKey
  1528.      *        parameter
  1529.      * @param translatedKey the translated version of the key string for
  1530.      *        displaying in user interfaces. Use i18n() to translate the string
  1531.      * @param type the type of the meta information item, e.g. QVariant::Int
  1532.      *        or QVariant::String.
  1533.      * @return an ItemInfo object. Pass this object to setAttributes()
  1534.      **/
  1535.     KFileMimeTypeInfo::ItemInfo* addItemInfo(KFileMimeTypeInfo::GroupInfo* gi,
  1536.                                              const QString& key,
  1537.                                              const QString& translatedKey,
  1538.                                              QVariant::Type type);
  1539.  
  1540.     /**
  1541.      * Sets some attributes for a meta information item. The attributes
  1542.      * describe if the item is mutable, how it should be computed for a list of
  1543.      * files, and how it should be displayed
  1544.      *
  1545.      * @param item the ItemInfo object as returned by addItemInfo()
  1546.      * @param attr the attributes for this item; these are values of type
  1547.      *        KFileMimeTypeInfo::Attributes, or'ed together
  1548.      **/
  1549.     void setAttributes(KFileMimeTypeInfo::ItemInfo* item, uint attr);
  1550.  
  1551.     /**
  1552.      * Defines the meaning of the meta information item. Some applications make
  1553.      * use of this information, so be sure to check KFileMimeTypeInfo::Hint to
  1554.      * see if an item's meaning is in the list.
  1555.      *
  1556.      * @param item the ItemInfo object as returned by addItemInfo()
  1557.      * @param hint the item's meaning. See KFileMimeTypeInfo::Hint for a list
  1558.      *        of available meanings
  1559.      **/
  1560.     void setHint(KFileMimeTypeInfo::ItemInfo* item, uint hint);
  1561.  
  1562.     /**
  1563.      * Sets the unit used in the meta information item. This unit is used to
  1564.      * format the value and to make large values human-readable. For example,
  1565.      * if the item's unit is KFileMimeTypeInfo::Seconds and the value is 276,
  1566.      * it will be displayed as 4:36.
  1567.      *
  1568.      * @param item the ItemInfo object as returned by addItemInfo()
  1569.      * @param unit the item's unit. See KFileMimeTypeInfo::Unit for a list of
  1570.      *        available units
  1571.      **/
  1572.     void setUnit(KFileMimeTypeInfo::ItemInfo* item, uint unit);
  1573.  
  1574.     /**
  1575.      * Sets a prefix string which is displayed before the item's value. Use
  1576.      * this string if no predefined unit fits the item's unit. Be sure to
  1577.      * translate the string with i18n()
  1578.      *
  1579.      * @param item the ItemInfo object as returned by addItemInfo()
  1580.      * @param prefix the prefix string to display
  1581.      **/
  1582.     void setPrefix(KFileMimeTypeInfo::ItemInfo* item, const QString& prefix);
  1583.  
  1584.     /**
  1585.      * Sets a suffix string which is displayed before the item's value. Use
  1586.      * this string if no predefined unit fits the item's unit. Be sure to
  1587.      * translate the string with i18n()
  1588.      *
  1589.      * @param item the ItemInfo object as returned by addItemInfo()
  1590.      * @param suffix the suffix string to display
  1591.      **/
  1592.     void setSuffix(KFileMimeTypeInfo::ItemInfo* item, const QString& suffix);
  1593.  
  1594.     /**
  1595.      * Call this method from within readInfo() to indicate that you wish to
  1596.      * fill meta information items of the group identified by @p key with
  1597.      * values.
  1598.      *
  1599.      * @param info the KFileMetaInfo object. Use the parameter of the
  1600.      *        readInfo() method
  1601.      * @param key the key string to identify the group. Use the string that you
  1602.      *        defined in your class' constructor
  1603.      * @return a KFileMetaInfoGroup object, to be used in appendItem()
  1604.      **/
  1605.     KFileMetaInfoGroup appendGroup(KFileMetaInfo& info, const QString& key);
  1606.  
  1607.     /**
  1608.      * Call this method from within readInfo() to fill the meta information item
  1609.      * identified by @p key with a @p value
  1610.      *
  1611.      * @param group the KFileMetaInfoGroup object, as returned by appendGroup()
  1612.      * @param key the key string to identify the item.
  1613.      * @param value the value of the meta information item
  1614.      **/
  1615.     void appendItem(KFileMetaInfoGroup& group, const QString& key, QVariant value);
  1616.  
  1617.     QStringList m_preferredKeys;
  1618.     QStringList m_preferredGroups;
  1619.  
  1620. protected:
  1621.     /**
  1622.      * Helper method to allow binary compatible extensions when needing
  1623.      * "new virtual methods"
  1624.      *
  1625.      * @param id the identifier of the new "virtual" method
  1626.      * @param data any parameter data the new "virtual" method needs
  1627.      */
  1628.     virtual void virtual_hook( int id, void* data );
  1629. private:
  1630.     class KFilePluginPrivate;
  1631.     KFilePluginPrivate *d;
  1632. };
  1633.  
  1634. ///////////////////////////////////////////////////////////////////
  1635. ///////////////////////////////////////////////////////////////////
  1636.  
  1637.  
  1638. /**
  1639.  * @internal
  1640.  * Synchronous access to metadata of a local file. Usually, you don't want
  1641.  * to use this class for getting metainfo from a file. Use KFileMetaInfo
  1642.  *  directly. However, if you want to find out if a specific mimetype is
  1643.  *  supported and which groups and items are provided for it, you can ask
  1644.  *  the KFileMetainfoProvider for it.
  1645.  **/
  1646. class KIO_EXPORT KFileMetaInfoProvider: private QObject
  1647. {
  1648.     friend class KFilePlugin;
  1649.  
  1650.   Q_OBJECT
  1651. public:
  1652.     virtual ~KFileMetaInfoProvider();
  1653.  
  1654.     static KFileMetaInfoProvider * self();
  1655.  
  1656.     /**
  1657.      *  @return a pointer to the plugin that belongs to the specified mimetype,
  1658.      *  which means also load the plugin if it's not in memory
  1659.      */
  1660.     KFilePlugin * plugin( const QString& mimeType ); // KDE4: merge with method below
  1661.  
  1662.     /**
  1663.      *  @return a pointer to the plugin that belongs to the specified mimetype,
  1664.      *  for the given protocol.
  1665.      *  This loads the plugin if it's not in memory yet.
  1666.      */
  1667.     KFilePlugin * plugin( const QString& mimeType, const QString& protocol );
  1668.  
  1669.     const KFileMimeTypeInfo * mimeTypeInfo( const QString& mimeType ); // KDE4: merge with below
  1670.     const KFileMimeTypeInfo * mimeTypeInfo( const QString& mimeType, const QString& protocol );
  1671.  
  1672.     QStringList preferredKeys( const QString& mimeType ) const;
  1673.     QStringList preferredGroups( const QString& mimeType ) const;
  1674.  
  1675.     /// @since 3.1
  1676.     QStringList supportedMimeTypes() const;
  1677.  
  1678. protected: // ## should be private, right?
  1679.     KFileMetaInfoProvider();
  1680.  
  1681. private:
  1682.  
  1683.     // Data structure:
  1684.     // Mimetype or Protocol -> { Plugin and MimeTypeInfo }
  1685.     // The {} struct is CachedPluginInfo
  1686.     struct CachedPluginInfo
  1687.     {
  1688.         CachedPluginInfo() : plugin( 0 ), mimeTypeInfo( 0 ), ownsPlugin( false ) {}
  1689.         CachedPluginInfo( KFilePlugin* p, KFileMimeTypeInfo* i, bool owns )
  1690.             : plugin( p ), mimeTypeInfo( i ), ownsPlugin( owns ) {}
  1691.         // auto-delete behavior
  1692.         ~CachedPluginInfo() {
  1693.             if ( ownsPlugin ) delete plugin;
  1694.             delete mimeTypeInfo;
  1695.         }
  1696.  
  1697.         // If plugin and mimeTypeInfo are 0, means that no plugin is available.
  1698.         KFilePlugin* plugin;
  1699.         KFileMimeTypeInfo* mimeTypeInfo;
  1700.         // The problem here is that plugin can be shared in multiple instances,
  1701.         // so the memory management isn't easy. KDE4 solution: use KSharedPtr?
  1702.         // For now we flag one copy of the KFilePlugin pointer as being "owned".
  1703.         bool ownsPlugin;
  1704.     };
  1705.  
  1706.     // The key is either a mimetype or a protocol. Those things don't look the same
  1707.     // so there's no need for two QDicts.
  1708.     QDict<CachedPluginInfo> m_plugins;
  1709.  
  1710.     // This data is aggregated during the creation of a plugin,
  1711.     // before being moved to the appropriate CachedPluginInfo(s)
  1712.     // At any other time than during the loading of a plugin, this dict is EMPTY.
  1713.     // Same key as in m_plugins: mimetype or protocol
  1714.     QDict<KFileMimeTypeInfo> m_pendingMimetypeInfos;
  1715.  
  1716. private:
  1717.     static KFileMetaInfoProvider * s_self;
  1718.  
  1719.     KFilePlugin* loadPlugin( const QString& mimeType, const QString& protocol );
  1720.     KFilePlugin* loadAndRegisterPlugin( const QString& mimeType, const QString& protocol );
  1721.     KFileMimeTypeInfo * addMimeTypeInfo( const QString& mimeType );
  1722.  
  1723.     class KFileMetaInfoProviderPrivate;
  1724.     KFileMetaInfoProviderPrivate *d;
  1725.  
  1726. };
  1727.  
  1728. KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfoItem& );
  1729. KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfoItem& );
  1730.  
  1731. KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfoGroup& );
  1732. KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfoGroup& );
  1733.  
  1734. KIO_EXPORT QDataStream& operator <<(QDataStream& s, const KFileMetaInfo& );
  1735. KIO_EXPORT QDataStream& operator >>(QDataStream& s, KFileMetaInfo& );
  1736.  
  1737.  
  1738. #endif // KILEMETAINFO_H
  1739.